//
//  BKXXDianMingCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/24.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "BKXXDianMingCell.h"

@implementation BKXXDianMingCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    CGFloat W = self.frame.size.width/7;
    for (int i = 0; i<7; i++){
        if (i==6) {
            self.selectedAllButton.frame = CGRectMake(30+W*i,0,W,44);
            [self addSubview:_selectedAllButton];
        }else{
            UILabel *label = [[UILabel alloc] init];
            label.frame = CGRectMake(30+W*i,0,W,44);
            label.numberOfLines = 0;
            label.textAlignment = 1;
            label.text = _dataArray[i];
            label.tag = 30+i;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [UIColor darkGrayColor];
            [self addSubview:label];
        }
    }
}
- (void)reloadViewLayout{
    CGFloat W = self.frame.size.width/7;
    CGFloat X = W-15;
    for (int i = 0; i<7; i++){
        if (i==6) {
            _selectedAllButton.frame = CGRectMake(30+X*i+30+W/2-9.5,44/2-9.5,19,19);
        }else{
            UILabel *label = (UILabel *)[self viewWithTag:i+30];
            if (i<_dataArray.count-2) {
                label.frame = CGRectMake(30+X*i,0,X,44);
            }else if (i == _dataArray.count-2){
                label.frame = CGRectMake(30+X*i,0,X+30,44);
            }
            label.text = _dataArray[i];
        }
    }
}
- (UIButton *)selectedAllButton{
    if (!_selectedAllButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitleColor:TITLECOLOR forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"fudao_dianming_normol"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"fudao_dianming_selected"] forState:UIControlStateSelected];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button addTarget:self action:@selector(selectedALL:) forControlEvents:UIControlEventTouchUpInside];
        _selectedAllButton = button;
    }
    return _selectedAllButton;
}
- (void)selectedALL:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected == YES) {
        self.block([NSString stringWithFormat:@"%ld",(long)_indexPath.row]);
    }else{
        self.deleteBlock([NSString stringWithFormat:@"%ld",(long)_indexPath.row]);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
